package demo.aj;

import demo.model.Account;


public aspect AccountAspect {

    pointcut callPayCheck(int amount, Account account):
                call(boolean Account.pay(int)) && args(amount) && target(account);

        before(int amount, Account account): callPayCheck(amount, account) {
            System.out.println("[AccountAspect]付款前总金额: " + account.balance);
            System.out.println("[AccountAspect]需要付款: " + amount);
        }

        boolean around(int amount, Account account): callPayCheck(amount, account) {
            if (account.balance < amount) {
                System.out.println("[AccountAspect]拒绝付款!");
                return false;
            }
            return proceed(amount, account);
        }

        after(int amount, Account balance): callPayCheck(amount, balance) {
            System.out.println("[AccountAspect]付款后，剩余：" + balance.balance);
        }
}